<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../../core/treegrid/themes/default/easyui.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <link rel="stylesheet" href="../../core/lib/treeTable/treeTable.css">
    <style>
        .datagrid-header, .datagrid-toolbar, .datagrid-pager, .datagrid-footer-inner {
            border-color: white !important;
        }
        .datagrid-toolbar, .datagrid-pager {
            background: white !important;
        }
        .layui-form-select dl {
            max-height: 120px;
        }
        .layui-form-label {
            padding: 9px 15px !important;
            width: 90px !important;
        }
    </style>

</head>
<body >
<div class="layui-fluid" id="flowDiv" onload="onLoad()" >
    <div class="zTreeBackground left" style="float: left;width:300px">
        <div class="titlediv">
            <p style="text-align:right;background-color:white;line-height: 30px">
                专业领域信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="searchByName()"></i>&ensp;&ensp;
            </p>

        </div>
        <div class="searchdiv" >
            <div class="layui-input-inline" style="width:100%">
                <input type="text" id="keyword" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="searchByName()"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv" style="overflow:auto">
            <ul id="treeStructure" class="ztree"></ul>
        </div>
    </div>
    <div class="zTreeBackground right" style="float: left;width:65%; padding-left:1%">
        <div class="layui-form-item" style="width:99%;margin-bottom:-10px;text-align:right;">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 90px !important;">名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name1" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
                    <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="easysearch()"></i>
                </div>
            </div>
            <button type="button" style="margin-left:12px;margin-top: -12px;" class="layui-btn layui-btn-normal" onclick="moresearch()"><i class="layui-icon layui-icon-search"></i>高级搜索</button>
        </div>
        <div class="search_float_div" style="position:absolute;z-index:999;width:79%;background-color: #f1f1f1;padding-top: 20px;padding-bottom:50px;text-align:left;display:none">
            <div class="layui-form-item layui-form">
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" style="float: left"  id="name"   placeholder="请输入名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">展开层级</label>
                    <div class="layui-input-inline">
                        <select class="layui-input" id="hierarchy">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="searchTable()"><i class="layui-icon layui-icon-search"></i>查询</button>
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="resetSearchTable()"><i class="layui-icon layui-icon-search"></i>重置</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="canclesearch()">取消</button>
                </div>
            </div>
        </div>

        <div id="buttongroup" style="display: none;margin-top: 10px">
        </div>

        <table class="layui-table layui-form" id="datatable" lay-filter="data-table">
        </table>

    </div>
</div>
</body>
<SCRIPT type="text/javascript">
    window.onload = getContentSize;
    window.onresize = getContentSize;
    var checkFlag = true;
    var checkFlag2 = true;

    //初始化标志位
    var initFlag=false,zTreeObj,form,treeTable,insTb,disciplinesId='',disciplinesName='';

    layui.config({
        base: publicResourceUrl+'core/lib/treeTable/'//模块存放的目录
    }).use(['jquery','element','form','layer','treeTable'],function () {
        var $ = layui.jquery,
            element = layui.element,
            layer = layui.layer;
        treeTable = layui.treeTable;
        form = layui.form;
        //loadSelect();
        //console.info(treeTable);
    });

    $(document).ready(function(){
        loadbutton();//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        loadTree();
        /**
         * 扩展树表格级联勾选方法：
         * @param {Object} container
         * @param {Object} options
         * @return {TypeName}
         */
    });


    function importEntElementTree(){
        var iframeWin ;
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        layer.open({
            type: 2,
            area: ["500px" , "350px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "导入EBS",
            content: "./importEntElementTree.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.getdisciplineId(disciplinesId);//添加按钮
            }
        });
    }

    /**
     * 模糊查询
     */
    function searchByName(){
        loadTree($("#keyword").val(),$("#keyword").val()==""?0:1);
    }

    /**
     * 点击触发
     * @param event
     * @param treeId
     * @param treeNode
     */
    function zTreeOnClick(event, treeId, treeNode) {
        if(treeNode.type==1){
            return;
        }
        if(treeNode.id==-1){
            return;
        }
        disciplinesId=treeNode.id;
        disciplinesName=treeNode.name;
        setMaxHierarchy(disciplinesId);
        //根据树的点击确定是专业还是领域
        loadTable();
        initFlag=true;
    };

    function setMaxHierarchy(disciplinesId){
        publicAjax ("post","resEntElementTree/getMaxHierarchy",{disciplinesId:disciplinesId},null,null,function (r) {
            var html="";
            for(var i=1;i<=r.data;i++){
                html+="<option value='"+i+"'>"+i+"</option>";
            }
            html+="<option value='-1' selected='selected'>ALL</option>";
            $("#hierarchy").html(html);
            form.render('select');
        });

    }


    /* *
     * @Author bxf
     * @Description 高级搜索
     * @Date 17:34 2019/8/30
     * @param null
     * @return
     */
    function moresearch(){
        $(".search_float_div").slideToggle();
    }
    /* *
     * @Author bxf
     * @Description 简单查询
     * @Date 17:46 2019/8/30
     * @param null
     * @return
     */
    function easysearch(){
        var hierarchy=-1;
        var name = $("#name1").val();
        queryByTable(name,hierarchy);
    }
    /* *
     * @Author bxf
     * @Description 取消查询
     * @Date 17:44 2019/8/30
     * @param null
     * @return
     */
    function canclesearch(){
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 重置查询
     * @Date 10:40 2019/10/29
     * @param null
     * @return
     */
    function resetSearchTable() {
        $("#hierarchy").val("");
        $("#name").val("");
        searchTable();
    }
    /* *
     * @Author bxf
     * @Description 搜索table数据
     * @Date 17:51 2019/8/30
     * @param null
     * @return
     */
    function searchTable(){
        var name=$("#name").val();
        var hierarchy=$("#hierarchy").val();
        queryByTable(name,hierarchy);
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 加载左侧table
     * @Date 17:46 2019/7/23
     * @param null
     * @return
     */
    function queryByTable(name,hierarchy){

        if(name!=null&&name!=""){
            loadTable(name,hierarchy,"queryName");
        }else{
            loadTable(name,hierarchy,"queryHierarchy");
        }

    }

    function loadTable(name,hierarchy,type) {
        var width = $(".left-nav").css("width");
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理
        $(".search_float_div").css("width",($(document).width()-350)+'px');//自适应搜索

        //初始化显示两节点
        if(type==null||type==''){
            type="queryHierarchy";//查询级别
        }
        if(hierarchy==null||hierarchy==''){
            hierarchy=1;//打开级别
        }
        // 渲染表格
        insTb = treeTable.render({
            elem: '#datatable',
            toolbars:"#buttongroup",
            height: 'full-200',
            tree: {
                arrowType: 'arrow3',   // 自定义箭头风格
                iconIndex: 1,  // 折叠图标显示在第几列
                idName: 'id',  // 自定义id字段的名称
                pidName: 'parentId',  // 自定义标识是否还有子节点的字段名称
                haveChildName: 'haveChild',  // 自定义标识是否还有子节点的字段名称
                isPidData: true,  // 是否是pid形式数据
                openName: 'state',
                getIcon: function(d) {  // 自定义图标
                    // d是当前行的数据
                    if (d.haveChild) {  // 判断是否有子集
                        return '<i class="ew-tree-icon ew-tree-icon-folder"></i>';
                    } else {
                        return '<i class="ew-tree-icon ew-tree-icon-file"></i>';
                    }
                }
            },
            text: {},
            cols: [
                {type: 'checkbox'},
                {
                    field: 'name',
                    title: '名称',
                    width: "20%",
                    align: 'left'
                },
                {
                    field: 'hierarchy',
                    title: '层级',
                    width: "5%",
                    align: 'center',
                },
                {
                    field: 'ebs',
                    title: 'EBS编码',
                    width: "15%",
                    align: 'center',
                    templet: function(row){
                        return "<span data-flag='"+row.ebs+"'>"+row.ebs+"</span>";
                    }
                },
                {
                    field: 'unit',
                    title: '单位',
                    width: "8%",
                    align: 'center',
                },
                {
                    field: 'ifd',
                    title: 'IFD编码',
                    width: "15%",
                    align: 'center',
                },
                {
                    field: 'relMethods',
                    title: '关联工法',
                    width: "8%",
                    align: 'center',
                    templet: function(row){
                        if (row.relMethods==1){
                            return '√';
                        } else {
                            return 'X';
                        }
                    }
                },
                {
                    field: 'comment',
                    title: '备注',
                    width: "20%",
                    align: 'center',
                },
                {
                    field: 'creator',
                    title: '工法详情',
                    width: "10%",
                    align: 'center',
                    templet: function(row){
                        if (row.relMethods==1){
                            return '<img onclick=showMethod("'+row.ebs+'") style="width: 20px;height: 20px" src="../../core/images/find.png" alt="查看" />';
                        }else{
                            return "";
                        }
                    }
                }
            ],
            reqData: function (data, callback) {
                var param = {};
                if(data){
                    param = {parentId: data.id,disciplinesId:disciplinesId,type:"async"};
                }else{
                    param = {'disciplinesId': disciplinesId,'type': type,'name':name,'hierarchy':hierarchy};
                }
                publicAjax(null,"resEntElementTree/selectAllResEntElementTree",param,null,null,function(r){
                    callback(r.data);

                })
            },
            style: 'margin-top:0;'
        });


        setTimeout(function () {
            $('body').children('.page-loading').hide();
            $('body').removeClass('page-no-scroll');
            //insTb.expandAll();  // 展开全部
        }, 100);

    }


    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理
        $(".search_float_div").css("width",($(document).width()-350)+'px');//自适应搜索
        delayLoad(function () {
            $('#datatable').treegrid('resize', {
                width:function(){ return $(document).width() -350;}
            });
        },1000)
    }




    /**
     * 左侧树设置
     * @type {{check: {enable: boolean}, data: {simpleData: {enable: boolean, idKey: string, pIdKey: string, isParent: string, rootPid: number}}, callback: {beforeClick: zTreeBeforeClick, onClick: zTreeOnClick}}}
     */
    var setting = {
        check: {
        },
        edit:{
            enable: false,
        },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"pid",
                isParent:"parent",
                rootPid:-1
            },
            key: {
                url: "xUrl",
                icon:"xIcon"
            }
        },
        callback: {
            onClick: zTreeOnClick
        }
    };





    /**
     * 模糊查询
     */
    function query(){
        loadTree($("#keyword").val(),$("#keyword").val()==""?0:1);
    }

    /**
     * 加载左侧树
     * type 0:不展开节点
     *      1:展开全部节点
     *
     */
    function loadTree(keyWord,type){
        publicAjax (null,'infDisciplines/selectAllInfDisciplinesByTree',{name: keyWord},null,null,function (r) {
            var jsondata = r.data;
            var json = {"id":-1,"name":"专业领域", open:true};
            jsondata.push(json);
            zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, jsondata);
            if(type==1){
                zTreeObj.expandAll(true);
            }
        })
    }


    //新增
    //type 0:新增同级
    //     1:新增下级
    function add(callback,type){
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        var rows = insTb.checkStatus(false);
        if(rows.length!=1){
            layer.alert("请选择一行数据");
            return;
        }
        var reloadId="";
        if(rows[0].parentId==null||rows[0].parentId==""||rows[0].parentId==0){
            //刷新整体
            reloadId=-1;
        }else{
            if(type==1){
                reloadId=rows[0].id;
            }else{
                reloadId=rows[0].parentId;
            }
        }

        var url='./addResEntElementTree.html?id='+rows[0].id+"&disciplinesName="+disciplinesName+"&type="+type+"&disciplinesId="+disciplinesId;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero);
                if(result.code==2000){
                    laysuccess("新增成功");
                }else{
                    layerror("新增失败");
                }
                layer.close(index);
                reloadTable(reloadId);
            }
        }
        layer.open({
            type: 2,
            area: ['640px', '620px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "新增企业级EBS",
            content: url,
            btn: ['应用', '完成','关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero,'applye');
                reloadTable(reloadId);
                return false;
            },
            btn2:callback,
            cancel: function(index) {
                return true;
            }
        });
    }

    function reloadTable(id){
        if(id == -1){
            loadTable();
        }else{
            insTb.refresh(id);
        }
    }


    //显示详情
    function show(obj,callback){
        var url='./editinfdisciplines.html?id='+obj.data.id+"&pName="+pName;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submit(index, layero);
                layer.close(index);
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }

            }
        }
        layer.open({
            type: 2,
            area: ['640px', '620px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "修改企业级EBS",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            cancel: function(index) {
                return true;
            }
        });
    }
    //显示详情
    function showMethod(ebs,callback){
        var url='./resmethods.html?ebs='+ebs+"";
        layer.open({
            type: 2,
            area: ['1350px', '650px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "查看工法",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            cancel: function(index) {
                return true;
            }
        });
    }


    //批量删除
    function del(){
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        var rows = insTb.checkStatus(false);
        //根节点
        if(rows.length==0){
            layer.alert("请选择数据");
            return;
        }
        var ids=[];
        for(var i=0;i<rows.length;i++){
            ids[i]=rows[i].id;
        }
        layer.confirm('你确认删除么?', {icon: 3, title:'提示'}, function(index){
            layer.close(index);
            publicAjax (null,'resEntElementTree/deleteResEntElementTreeByID',{ids: ids},null,null,function (r) {
                if(r.code==2000){
                    laysuccess("删除成功");
                }else{
                    layerror("删除失败");
                }
                reloadTable(-1);
            })
        });
    }

    //同步工法库
    function sync(){
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        layer.confirm('你确认同步么?同步工法库会删除原有关系，重新建立连接。', {icon: 3, title:'提示'}, function(index){
            layer.close(index);
            var index=layer.load(1, {shade: [0.4, '#A9A9A9']});
            publicAjax (null,'resEntElementTree/syncResEntElementTree',{disciplinesId:disciplinesId},null,null,function (r) {
                layer.close(index);
                if(r.code==2000){
                    laysuccess("同步成功");
                }else{
                    layerror("同步失败");
                }
                reloadTable(-1);
            })
        });
    }

    //移动
    function move(callback){
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        var rows = insTb.checkStatus(false);
        if(rows.length!=1){
            layer.alert("请选择一行数据");
            return;
        }
        for(var i=0;i<rows.length;i++){
            if(rows[i].parentId!=0){
                layer.alert("只允许移动根节点");
                return;
            }
        }

        var url='./moveResEntElementTree.html?id='+rows[0].id;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero);
                if(result.code==2000){
                    laysuccess("移动成功");
                }else{
                    layerror("移动失败");
                }
                layer.close(index);
                reloadTable(-1);
            }
        }
        layer.open({
            type: 2,
            area: ['400px', '550px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "移动到其他专业",
            content: url,
            btn: ['确定','应用', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: callback,
            btn2:function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero,'applye');
                reloadTable(-1);
                return false;
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    //修改成功后，刷新数据
    function editTableRow(result){
        $('#datatable').treegrid('update',{
            id: result.data.id,
            row: {
                'name': result.data.name,
                'hierarchy':result.data.hierarchy,
                'ebs':result.data.ebs,
                'unit':result.data.unit,
                'ifd':result.data.ifd,
                'comment':result.data.comment
            }
        });
    }

    //修改
    function edit(callback){
        if(''==disciplinesId){
            layer.alert("请选择专业");
            return;
        }
        var rows = insTb.checkStatus(false);
        if(rows.length!=1){
            layer.alert("请选择一行数据");
            return;
        }
        var reloadId=rows[0].id;
        var url='./editResEntElementTree.html?id='+rows[0].id+"&disciplinesName="+disciplinesName;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero);
                if(result.code==2000){
                    laysuccess("修改成功");
                }else{
                    layerror("修改失败");
                }
                layer.close(index);
                editTableRow(result)
            }
        }
        layer.open({
            type: 2,
            area: ['640px', '620px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "修改企业级EBS",
            content: url,
            btn: ['确定','应用', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: callback,
            btn2:function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero,'applye');
                editTableRow(result)
                return false;
            },
            cancel: function(index) {
                return true;
            }
        });
    }
    function isEmpty(value) {
        if (value == null || this.trim(value) == "") {
            return true;
        }
        return false;
    }
</SCRIPT>
</html>